<?php

namespace app\admin\model;

use think\Db;
use think\Model;

class SystemUser extends Model
{

    protected  $name = 'system_user';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = '';
    protected $updateTime = '';

    public static function SystemUserAdd($ids, $uid, $params = [], $type = '')
    {
        if (!$params['opinion'])
        {
            $params['opinion'] = $params['status'] == 1 ? '审核通过' : '审核未通过:请检查提交信息或联系客服询问';
        }

        if ($type == 'shop')
        {
            $userId = Db::name('user_shop')->where('id',$ids)->value('uid');
        }else{
            $userId = Db::name('user_agent')->where('id',$ids)->value('uid');
        }

        $time = time();
        $data = [
            'admin_id' => $uid,
            'shop_id'  => $ids,
            'user_id'  => $userId,
            'content'  => $params['opinion'],
            'status'   => $params['status'],
            'type'     => $type,
            'create_time' => $time,
        ];

        $response = Db::name('system_user')->insertGetId($data);

        if ($response)
        {
            return true;
        }else{
            return false;
        }


    }

}
